#include "core_pch.h"
#include "core.h"
#include "RawBuf.h"

void RawBuf::_resizeBuf( s32_t newSize ,s32_t eleSize)
{
	mBuf = coreRealloc( mBuf, mCap*eleSize, newSize*eleSize);
	mCap = newSize;
}

void RawBuf::RemoveAt( s32_t index, s32_t cnt, s32_t eleSize )
{
	if( cnt )
	{
		coreMemmove( (u8_t*)mBuf + (index) * eleSize,
			(u8_t*)mBuf + (index+cnt) * eleSize,
			(mNum - index - cnt ) * eleSize);
		mNum -= cnt;
		if(	(3*mNum<2*mCap || (mCap-mNum)*eleSize>=16384)
		&&	(mCap-mNum>64 || mNum==0) )
		{
			_resizeBuf( mNum, eleSize );
		}
	}
	_check(mNum>=0);
	_check(mCap>=mNum);
}
